<template>
  <div class="withdraw flex flex-column">
    <van-nav-bar
      title="提现"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
      right-text="提现明细"
      @click-right="onClickRight"
    />
    <div class="balance">可用余额：{{ account.avaiBalance }}积分</div>
    <van-cell-group inset>
      <van-field
        v-model="amount"
        type="number"
        label-width="0"
        label=""
        placeholder="请输入提现金额"
        show-word-limit
      />
      <van-notice-bar :scrollable="false" color="#ff976a" background="#fff" left-icon="info-o" style="padding:0;border:0;height: 24px;font-size:.12rem">
        {{ sys_msg.withdrawInfo }}
      </van-notice-bar>
    </van-cell-group>
    <van-button type="primary" @click="withdraw">提现</van-button>
  </div>
</template>
<script lang="ts" name="ChildView" setup>
import { showNotify } from 'vant'
import { inject, ref } from 'vue'
import { getCurrentInstance } from '@vue/runtime-core'
const $ajax: any = inject('$ajax')
const $api: any = inject('$api')
const currentInstance: any = getCurrentInstance()
const $this = currentInstance.proxy
import { useRouter } from 'vue-router'
const router = useRouter()
// import { changeNum } from '@/store'
// import { storeToRefs } from 'pinia'
// const store = changeNum()
// const { num } = storeToRefs(store)
// const clickChange = () => {
//   let random = Math.floor(Math.random() * 10 + 1)
//   store.CHANGE_COUNT(random)
// }
//用户信息
let user: any = ref({})
let personal_count: any = ref({})
let account: any = ref({})
let sys_msg: any = ref({})
let amount = ref()
async function get_detail() {
  const data = await $ajax({
    api: $api.detail
  })
  user.value = data.data.userInfo
  account.value = data.data.account
  personal_count.value = data.data.personalCount
}

get_detail()
//系统消息
async function get_sys_msg() {
  const data = await $ajax({
    api: $api.sys_msg
  })
  let msg_list = data.data.sysConfigInfo
  msg_list.forEach(({key,configInfo}: any) => {
    sys_msg.value[key]=configInfo
  })
}
get_sys_msg()
//开始做单
async function withdraw() {
  if (!amount.value || amount.value.length === 0) {
    showNotify({ type: 'danger', message: '提现金额不能为空！' })
    return
  }
  if (amount.value && amount.value > account.value.avaiBalance) {
    showNotify({ type: 'danger', message: '提现金额不能大于可用余额！' })
    return
  }
  await $ajax({
    api: $api.withdraw,
    data: { amount: amount.value }
  })
  showNotify({ type: 'success', message: '提交成功！' })
  get_detail()
}
//返回
const onClickLeft = () => {
  history.back()
}
function onClickRight() {
  router.push('/withdraw-list')
}
</script>
<style lang="less" scoped>
.withdraw {
  :deep(.van-cell) {
    .van-cell__value {
      flex: 3;
      font-size: 0.13rem;
    }
  }
  .balance {
    font-size: 0.13rem;
    padding: 0.1rem 0.3rem;
  }
}
:deep(.van-button) {
  width: calc(100% - 0.6rem);
  margin-left: 0.3rem;
  margin-top: 0.4rem;
  height: 0.4rem;
}
</style>
